<?php 
// +----------------------------------------------------------------------
// | RXThinkCMF框架 [ RXThinkCMF ]
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 南京RXThinkCMF研发中心
// +----------------------------------------------------------------------
// | 官方网站: http://www.rxthink.cn
// +----------------------------------------------------------------------
// | Author: 牧羊人 <1175401194@qq.com>
// +----------------------------------------------------------------------

namespace app\admin\service;


use app\admin\model\OfPatent;
use app\common\service\BaseService;
use think\facade\Db;

/**
 * 专利管理-服务类
 * @author 牧羊人
 * @since: 2021/12/24
 * Class OfPatentService
 * @package app\admin\service
 */
class OfPatentService extends BaseService
{
    /**
     * 构造函数
     * LevelService constructor.
     */
    public function __construct()
    {
        $this->model = new OfPatent();
    }
	
	/**
     * 获取数据列表
     * @return array
     * @since 2021/12/24
     * @author 牧羊人
     */
    public function getList()
    {
        $param = request()->param();

        // 查询条件
        $map = [];
		
        // 客户名称
        $company_id = isset($param['company_id']) ? trim($param['company_id']) : '';
        if ($company_id) {
            $map[] = ['company_id', '=', $company_id];
        }else{            
            //原先专利无代理人 选项  但是项目都跟客户挂钩  所以 查询都是查询客户为主 
            $admin_id = session("adminId");
            if($admin_id != 1){           
                $wh_or = [];
                $wh_or[] = ["service_id","=",$admin_id];
                $wh_or[] = ["agent_id","=",$admin_id];
                $wh_or[] = ["peer_id","=",$admin_id];
                $arr_ids = Db::name("of_company")->where('mark',1)->where(function($query) use($wh_or){$query->whereOr($wh_or);})->column("id");
                if(!empty($arr_ids)){
                    $map[] = ['company_id', 'in', $arr_ids];            
                }
            }
        }
        // 合同ID
        $contract_id = isset($param['contract_id']) ? trim($param['contract_id']) : '';
        if ($contract_id) {
            $map[] = ['contract_id', '=', $contract_id];
        }
        // 案件名称
        $number = isset($param['number']) ? trim($param['number']) : '';
        if ($number) {
            $map[] = ['number', 'like', "%{$number}%"];
        }
        // 内部编号
        $application_number = isset($param['application_number']) ? trim($param['application_number']) : '';
        if ($application_number) {
            $map[] = ['application_number', 'like', "%{$application_number}%"];
        }
        $status = isset($param['status']) ? trim($param['status']) : '';
        if ($status!=='') {
            $map[] = ['status', '=', $status];
        }
        // 判断是否未监控数据
        $issue_date = isset($param['issue_date']) ? trim($param['issue_date']) : '';
        if ($issue_date==2) {
            $map[] = ['issue_date', '=', ''];
        }
        // 判断是否未监控数据
        $new_status = isset($param['new_status']) ? trim($param['new_status']) : '';
        if ($new_status) {
            $map[] = ['new_status', '=', $new_status];
        }        
        $order = '';     
        if(isset($param['field'])){
            if($param['field'] == 'dao'){
                $order = 'reply_limit '.$param['order'];
            }
        }
        
        return parent::getList($map,$order); // TODO: Change the autogenerated stub
    }


                                                                            
}